package cn.fl.ref.fncprjeaplysettle.controller;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.upload.api.IUploadApiService;
import cmm.comm.facade.upload.condition.SysUlDatCfgQueryCondition;
import cmm.comm.facade.upload.dto.SysUlDatCfgDTO;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.ref.fnccappayeeinfo.service.IFncCapPayeeInfoService;
import cn.fl.ref.fncprjbscinfo.service.IFncPrjBscInfoService;
import cn.fl.ref.fncprjbscinfo.vo.FncPrjBscInfoVO;
import cn.fl.ref.fncprjeaplysettle.service.IFncPrjEaplySettleService;
import cn.fl.ref.fncprjeaplysettle.transform.SettlePrjDetailVOTransform;
import cn.fl.ref.fncprjeaplysettle.vo.FncPrjEaplySettleVO;
import cn.fl.ref.fncprjeaplysettle.vo.FncPrjPayTbInfoVO;
import cn.fl.ref.fncprjeaplysettle.vo.SettlePrjDetailVO;
import cn.fl.ref.fncprjfstpyinfo.service.IFncPrjFstpyInfoService;
import cn.fl.ref.fribaseinfo.service.IFriBaseInfoService;
import cn.fl.ref.fribaseinfo.transform.BankAccInfoVOTransform;
import cn.fl.ref.fribaseinfo.vo.BankAccInfoVO;
import cn.fl.ref.fribaseinfo.vo.FriBaseInfoVO;
import cn.fl.ref.mrgnmanageinfo.vo.MrgnDetailInfoVO;
import cn.fl.ref.scmbaseinfo.service.IScmBaseInfoService;
import cn.fl.ref.scmbaseinfo.vo.ScmBaseInfoVO;
import cn.fl.system.condition.SysBkAccInfoQueryCondition;
import cn.fl.system.constant.SysLogConstant;
import cn.fl.system.service.ISysBkAccInfoService;
import cn.fl.system.service.ISysUlFilesRecService;
import cn.fl.system.transform.SysUlDatCfgVOTransform;
import cn.fl.system.vo.SysBkAccInfoVO;
import cn.fl.system.vo.SysUlDatCfgVO;
import fl.customer.facade.customer.constant.CustomerConstant;
import fl.flow.facade.flow.constant.FlowConstant;
import fl.flow.facade.flow.dto.FlowStartParamsDTO;
import fl.flow.facade.flow.dto.FlowStartedDTO;
import fl.ref.crbaseinfo.constant.CrBaseInfoConstant;
import fl.ref.fncprjeaplysettle.condition.FncPrjEaplySettleQueryCondition;
import fl.ref.fncprjeaplysettle.constant.FncPrjEaplySettleConstant;
import fl.ref.fncprjeaplysettle.dto.SettlePrjDetailDTO;
import fl.ref.fribaseinfo.condition.BankAccInfoQueryCondition;
import fl.ref.fribaseinfo.condition.FriBaseInfoQueryCondition;
import fl.ref.fribaseinfo.dto.BankAccInfoDTO;
import fl.ref.fribaseinfo.service.IBankAccInfoApiService;
import fl.ref.mrgnmanageinfo.constant.MrgnManageInfoConstant;
import fl.ref.scmbaseinfo.condition.ScmBaseInfoQueryCondition;

/**
 * @Description: 正常结清
 */
@Controller
@RequestMapping("/rfbase/fncprjeaplysettle")  
public class FncPrjEaplylSettleController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(FncPrjEaplylSettleController.class);

	@Autowired
	private IFncPrjEaplySettleService fncPrjEaplySettleService;
	
	@Autowired
	private IFriBaseInfoService friBaseInfoService;

	@Autowired
	private IScmBaseInfoService scmBaseInfoService;
	
	@Autowired
	private IFncPrjFstpyInfoService fncPrjFstpyInfoService;
	@Autowired
	private IFncCapPayeeInfoService fncCapPayeeInfoService;
	/**
	 * 数据字典服务
	 */
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;
	
	/**
	 * 附件服务
	 */
	@Autowired
	private ISysUlFilesRecService sysUlFilesRecService;
	

	@Autowired
	private IUploadApiService uploadApiService;
	
	
	
	@Autowired
	private IFncPrjBscInfoService fncPrjBscInfoService;
	
	/**
	 * 融资机构银行帐号信息
	 */
	@Autowired
	private IBankAccInfoApiService bankAccInfoApiService;
	
	/**
	 * 狮桥支付银行账户
	 */
	@Autowired
	private ISysBkAccInfoService sysBkAccInfoService;


	/**
	 * 到列表页面
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET })
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		logger.info("加载正常结清列表页面.");
		ModelAndView view = new ModelAndView("/rfbase/fncprjeaplysettle/fncPrjEaplySettleList");
		// 融资机构
		List<FriBaseInfoVO> friBaseInfoVOs = friBaseInfoService.searchList(new FriBaseInfoQueryCondition());
		List<KeyValueVO> fundRasInsNmList = fncPrjFstpyInfoService.transformToKeyValue(friBaseInfoVOs, FriBaseInfoVO.class.getName(), "id",
				"fundRasInsNm");
		view.addObject("fundRasInsNmList", fundRasInsNmList);
		// 融资方案
		List<ScmBaseInfoVO> scmBaseInfoVOs = scmBaseInfoService.selectBscLstByCondition(new ScmBaseInfoQueryCondition());
		List<KeyValueVO> fncScmNmList = fncPrjFstpyInfoService.transformToKeyValue(scmBaseInfoVOs, ScmBaseInfoVO.class.getName(), "fncScmId",
				"fncScmNm");
		view.addObject("fncScmNmList", fncScmNmList);
		view.addObject("frilist", JSON.toJSONString(friBaseInfoVOs));//add by gengchunlan 20190606
		return view;
	}

	/**
	 * 初始化列表
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET })
	@ResponseBody
	public Object initList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String fncInsId = request.getParameter("fncInsId");
		String fncScmId = request.getParameter("fncScmId");
		String fncPrjNm = request.getParameter("fncPrjNm");
		String fncSettleStcd = request.getParameter("fncSettleStcd");

		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		FncPrjEaplySettleQueryCondition qc = new FncPrjEaplySettleQueryCondition();
		
		if (StringUtils.isNotEmpty(fncInsId)) {
			qc.setFncInsId(fncInsId);
		}
		if (StringUtils.isNotEmpty(fncScmId)) {
			qc.setFncScmId(fncScmId);
		}
		if (StringUtils.isNotEmpty(fncPrjNm)) {
			qc.setFncPrjNm(fncPrjNm);
		}
		if (StringUtils.isNotEmpty(fncSettleStcd)) {
			qc.setFncSettleStcd(fncSettleStcd);
		}
		page.setCondition(qc);

		Pager pager = this.fncPrjEaplySettleService.selectEaplySettlePrjListPage(page);
		List<SettlePrjDetailDTO> listDtos = (List<SettlePrjDetailDTO>) pager.getResultList();
		List<SettlePrjDetailVO> list = SettlePrjDetailVOTransform.toVOList(listDtos);
		ListPageVO<SettlePrjDetailVO> listPage = new ListPageVO<SettlePrjDetailVO>(list, pager.getTotalCount());

		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		return listPage;
	}
	
	/**
	 * 提前还款添加页面
	 */
	@RequestMapping(value = "/toPrjEaplySettlePage.do", method = { RequestMethod.GET})
	public ModelAndView toPrjEaplySettlePage(HttpServletRequest request, HttpServletResponse response) {
		
		logger.info("加载提前还款申请页面.");
		ModelAndView view = new ModelAndView("/rfbase/fncprjeaplysettle/fncPrjEaplySettleAdd");
		String prjLgcId = request.getParameter("prjLgcId");
		if (StringUtils.isEmpty(prjLgcId)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "项目信息编号不能为空!");
		}
		
		FncPrjBscInfoVO fncPrjBscInfoVO =this.fncPrjBscInfoService.selectById(Long.valueOf(prjLgcId));
		ArrayList esPdList =this.fncPrjEaplySettleService.selectPrjEsPdByPrjId(Long.valueOf(prjLgcId));
		
		String fncInsId=fncPrjBscInfoVO.getFncinsid();
		view.addObject("fncInsId", fncInsId);
		view.addObject("prjLgcId", prjLgcId);
		view.addObject("esPdList", esPdList);
		return view;
	}
	
	/**
	 * 提前还款页面-添加页面初始化
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/prjEaplySettlePageinit.do", method = { RequestMethod.POST})
	@ResponseBody
	public DataResultVO prjEaplySettlePageinit(HttpServletRequest request, HttpServletResponse response) {
		String prjLgcId = request.getParameter("prjLgcId");
		if (StringUtils.isEmpty(prjLgcId)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "项目信息编号不能为空!");
		}
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "获取成功!");
		Map<String, Object> map=new HashMap<String, Object>();
		try {
			SettlePrjDetailVO settlePrjDetail =this.fncPrjEaplySettleService.selectPrjInfoByPrjId(Long.valueOf(prjLgcId));
			List<FncPrjPayTbInfoVO> FncPrjPayTbInfoList =this.fncPrjEaplySettleService.selectPrjPayTbInfoList(Long.valueOf(prjLgcId));
			map.put("settlePrjDetail", settlePrjDetail);
			map.put("FncPrjPayTbInfoList", FncPrjPayTbInfoList);
			result.setData(map);
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "prjEaplySettlePageinit", "获取数据失败,项目逻辑编号["+prjLgcId+"]."+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误!");
			BaseLogUtils.error(logger, "prjEaplySettlePageinit", "获取数据失败,项目逻辑编号["+prjLgcId+"]."+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 提前还款-修改-页面
	 */
	@RequestMapping(value = "/toPrjEaplySettleUpdatePage.do", method = { RequestMethod.GET})
	public ModelAndView toPrjEaplySettleUpdatePage(HttpServletRequest request, HttpServletResponse response) {
		
		logger.info("加载提前还款申请页面.");
		ModelAndView view = new ModelAndView("/rfbase/fncprjeaplysettle/fncPrjEaplySettleAdd");
		String lgcId = request.getParameter("lgcId");
		if (StringUtils.isEmpty(lgcId)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "项目信息编号不能为空!");
		}
		SettlePrjDetailVO settlePrjDetail =this.fncPrjEaplySettleService.selectOnlyPrjInfoByPrjId(Long.valueOf(lgcId));
		Long fncInsId=settlePrjDetail.getFncInsId();
		Long prjLgcId=settlePrjDetail.getFncPrjId();
		ArrayList esPdList =this.fncPrjEaplySettleService.selectPrjEsPdByPrjId(prjLgcId);
		view.addObject("fncInsId", fncInsId);
		view.addObject("lgcId", lgcId);
		view.addObject("prjLgcId", prjLgcId);
		view.addObject("esPdList", esPdList);
		return view;
	}
	
	/**
	 * 提前还款-详情-页面-审核中
	 */
	@RequestMapping(value = "/toPrjEaplySettleDetailPage.do", method = { RequestMethod.GET})
	public ModelAndView toPrjEaplySettleDetailPage(HttpServletRequest request, HttpServletResponse response) {
		
		logger.info("加载提前还款详情页面.");
		ModelAndView view = new ModelAndView("/rfbase/fncprjeaplysettle/fncPrjEaplySettleDetail");
		String lgcId = request.getParameter("lgcId");
		if (StringUtils.isEmpty(lgcId)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "提前还款信息编号不能为空!");
		}
		view.addObject("lgcId", lgcId);
		return view;
	}
	
	/**
	 * 提前还款-修改-详情-页面初始化---审核中
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/prjEaplySettleUpdatePageinit.do", method = { RequestMethod.POST})
	@ResponseBody
	public DataResultVO prjEaplySettleUpdatePageinit(HttpServletRequest request, HttpServletResponse response) {
		String lgcId = request.getParameter("lgcId");
		String prjLgcId = request.getParameter("prjLgcId");
		if (StringUtils.isEmpty(lgcId)&&StringUtils.isEmpty(prjLgcId)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "提前还款逻辑编号不能为空!");
		}
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "获取成功!");
		Map<String, Object> map=new HashMap<String, Object>();
		SettlePrjDetailVO settlePrjDetail =new SettlePrjDetailVO();
		List<FncPrjPayTbInfoVO> FncPrjPayTbInfoList = new ArrayList<FncPrjPayTbInfoVO>();
		try {
			if (StringUtils.isNotEmpty(lgcId)) {
				settlePrjDetail =this.fncPrjEaplySettleService.selectEaplyInfoById(Long.valueOf(lgcId));
				Long prjLgcIdL=settlePrjDetail.getFncPrjId();
				FncPrjPayTbInfoList =this.fncPrjEaplySettleService.selectPrjPayTbInfoList(Long.valueOf(prjLgcIdL));
			}else{
				settlePrjDetail =this.fncPrjEaplySettleService.selectEaplyInfoByPrjId(Long.valueOf(prjLgcId));
				FncPrjPayTbInfoList =this.fncPrjEaplySettleService.selectPrjPayTbInfoList(Long.valueOf(prjLgcId));
			}
			//添加银行帐号信息
			FncPrjEaplySettleVO fncPrjEaplySettle=settlePrjDetail.getFncPrjEaplySettle();
			// 保证金收款帐户信息
			if (StringUtils.isNotEmpty(fncPrjEaplySettle.getRecvAcc())) {
				BankAccInfoDTO bankAccInfoDTO = bankAccInfoApiService.selectById(fncPrjEaplySettle.getRecvAcc(), CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
				if(bankAccInfoDTO!=null){
					BankAccInfoVO bankAccInfoVo =BankAccInfoVOTransform.toVO(bankAccInfoDTO);
					fncPrjEaplySettle.setReAccNm(bankAccInfoVo.getAccNm());
					fncPrjEaplySettle.setReBanAccNm(bankAccInfoVo.getBanAccNm());
					fncPrjEaplySettle.setReAccNum(bankAccInfoVo.getAccNum());
				}
			}
			
			// 我司付款帐户信息
			if (StringUtils.isNotEmpty(fncPrjEaplySettle.getPayAcc())) {
				SysBkAccInfoVO bkAccInfoVO = sysBkAccInfoService.selectById(fncPrjEaplySettle.getPayAcc());
				if(bkAccInfoVO!=null){
			    	fncPrjEaplySettle.setPayAccNm(bkAccInfoVO.getBkNm());
			 	    fncPrjEaplySettle.setPayAccNum(bkAccInfoVO.getAccNo());
				    fncPrjEaplySettle.setPayBanAccNm(bkAccInfoVO.getAccNm());
				}
			}
			settlePrjDetail.setFncPrjEaplySettle(fncPrjEaplySettle);
			map.put("settlePrjDetail", settlePrjDetail);
			map.put("FncPrjPayTbInfoList", FncPrjPayTbInfoList);
			result.setData(map);
		}catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "prjEaplySettleUpdatePageinit", "获取数据失败,提前还款逻辑编号["+lgcId+"]."+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误!");
			BaseLogUtils.error(logger, "prjEaplySettleUpdatePageinit", "获取数据失败,提前还款逻辑编号["+lgcId+"]."+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 由列表页面进入-详情页面-提前还款
	 */
	@RequestMapping(value = "/toPrjEaplySettleInfoListPage.do", method = { RequestMethod.GET})
	public ModelAndView toPrjEaplySettleInfoPage(HttpServletRequest request, HttpServletResponse response) {
		
		logger.info("加载提前还款详情页面.");
		ModelAndView view = new ModelAndView("/rfbase/fncprjeaplysettle/fncPrjEaplySettleDetail");
		String prjLgcId = request.getParameter("prjLgcId");
		if (StringUtils.isEmpty(prjLgcId)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "项目信息编号不能为空!");
		}
		view.addObject("prjLgcId", prjLgcId);
		return view;
	}
	
	/**
	 * 新增-主动还款信息
	 */
	@RequestMapping(value = "/addEaplySettleInfo.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object addEaplySettleInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
	
		String prjid = request.getParameter("prjid");
		String rmrk = request.getParameter("rmrk");
		String esPd = request.getParameter("esPd");
		String capital = request.getParameter("capital");
		String interest = request.getParameter("interest");
		String otherChar = request.getParameter("otherChar");
		String setlleChar = request.getParameter("setlleChar");
		String allChar = request.getParameter("allChar");
		String payTm = request.getParameter("payTm");
		String recvAcc = request.getParameter("recvAcc");
		String payAcc = request.getParameter("payAcc");
		String esPdInterest = request.getParameter("esPdInterest");
		
		FncPrjEaplySettleVO entity=new FncPrjEaplySettleVO();
		if (StringUtils.isNotEmpty(prjid)) {
			entity.setPrjid(Long.valueOf(prjid));
		}
		if (StringUtils.isNotEmpty(rmrk)) {
			entity.setRmrk(rmrk);
		}
		if (StringUtils.isNotEmpty(esPd)) {
			entity.setEsPd(Integer.valueOf(esPd));
		}
		if (StringUtils.isNotEmpty(capital)) {
			entity.setCapital(new BigDecimal(capital));
		}
		if (StringUtils.isNotEmpty(interest)) {
			entity.setInterest(new BigDecimal(interest));
		}
		if (StringUtils.isNotEmpty(otherChar)) {
			entity.setOtherChar(new BigDecimal(otherChar));
		}
		if (StringUtils.isNotEmpty(setlleChar)) {
			entity.setSetlleChar(new BigDecimal(setlleChar));
		}
		if (StringUtils.isNotEmpty(allChar)) {
			entity.setAllChar(new BigDecimal(allChar));
		}
		if (StringUtils.isNotEmpty(esPdInterest)) {
			entity.setEsPdInterest(new BigDecimal(esPdInterest));
		}
		if (StringUtils.isNotEmpty(payTm)) {
			Date s = DateUtils.formatStringToDate(payTm, DateUtils.YYYY_MM_DD);
			entity.setPayTm(s);
		}
		if (StringUtils.isNotEmpty(recvAcc)) {
			entity.setRecvAcc(Long.valueOf(recvAcc));
		}
		if (StringUtils.isNotEmpty(payAcc)) {
			entity.setPayAcc(Long.valueOf(payAcc));
		}
		entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
		entity.setCrtTm(new Date());
		entity.setIsValid(BaseConstant.IS_YESNO_NO); // 无效
		entity.setIsDel(BaseConstant.IS_YESNO_NO); // 未删除
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "保证金退回信息添加成功!");
		
		try {
			Long mainId = this.fncPrjEaplySettleService.add(entity);
			result.setData(mainId);
			//上传附件
			uploadAttchment(request, result, mainId);
			result.setSuccess(BaseConstant.IS_YESNO_YES);
			result.setInfo("提前退款信息添加成功!");
			BaseLogUtils.info(logger, "addEaplySettleInfo", "新增数据 ,项目逻辑序号:id["+prjid+"]. ID:"+mainId, CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "addEaplySettleInfo", "新增数据失败,项目逻辑序号:id["+prjid+"]."+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("新增失败!");
			BaseLogUtils.error(logger, "addEaplySettleInfo", "新增数据失败,项目逻辑序号:id["+prjid+"]."+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	/**
	 * 修改-主动还款信息
	 */
	@RequestMapping(value = "/updateEaplySettleInfo.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object updateEaplySettleInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
	
		String lgcId = request.getParameter("lgcId");
		String prjid = request.getParameter("prjid");
		String rmrk = request.getParameter("rmrk");
		String esPd = request.getParameter("esPd");
		String capital = request.getParameter("capital");
		String interest = request.getParameter("interest");
		String otherChar = request.getParameter("otherChar");
		String setlleChar = request.getParameter("setlleChar");
		String allChar = request.getParameter("allChar");
		String payTm = request.getParameter("payTm");
		String recvAcc = request.getParameter("recvAcc");
		String payAcc = request.getParameter("payAcc");
		String esPdInterest = request.getParameter("esPdInterest");
		
		FncPrjEaplySettleVO entity=new FncPrjEaplySettleVO();
		if (StringUtils.isNotEmpty(lgcId)) {
			entity.setId(Long.valueOf(lgcId));
		}
		if (StringUtils.isNotEmpty(prjid)) {
			entity.setPrjid(Long.valueOf(prjid));
		}
		if (StringUtils.isNotEmpty(rmrk)) {
			entity.setRmrk(rmrk);
		}
		if (StringUtils.isNotEmpty(esPd)) {
			entity.setEsPd(Integer.valueOf(esPd));
		}
		if (StringUtils.isNotEmpty(capital)) {
			entity.setCapital(new BigDecimal(capital));
		}
		if (StringUtils.isNotEmpty(interest)) {
			entity.setInterest(new BigDecimal(interest));
		}
		if (StringUtils.isNotEmpty(otherChar)) {
			entity.setOtherChar(new BigDecimal(otherChar));
		}
		if (StringUtils.isNotEmpty(setlleChar)) {
			entity.setSetlleChar(new BigDecimal(setlleChar));
		}
		if (StringUtils.isNotEmpty(esPdInterest)) {
			entity.setEsPdInterest(new BigDecimal(esPdInterest));
		}
		if (StringUtils.isNotEmpty(allChar)) {
			entity.setAllChar(new BigDecimal(allChar));
		}
		if (StringUtils.isNotEmpty(payTm)) {
			Date s = DateUtils.formatStringToDate(payTm, DateUtils.YYYY_MM_DD);
			entity.setPayTm(s);
		}
		if (StringUtils.isNotEmpty(recvAcc)) {
			entity.setRecvAcc(Long.valueOf(recvAcc));
		}
		if (StringUtils.isNotEmpty(payAcc)) {
			entity.setPayAcc(Long.valueOf(payAcc));
		}
		entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
		entity.setMdfTm(new Date());
		entity.setIsValid(BaseConstant.IS_YESNO_NO); // 有效
		entity.setIsDel(BaseConstant.IS_YESNO_NO); // 未删除
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "项目提前结清信息修改成功!");
		
		try {
			this.fncPrjEaplySettleService.modify(entity);
			//录入资金系统接口付款表--陈君
			//this.fncCapPayeeInfoService.addCapEaplySettle(Long.parseLong(lgcId));
			//上传附件
			uploadAttchment(request, result, Long.valueOf(lgcId));
			result.setSuccess(BaseConstant.IS_YESNO_YES);
			result.setInfo("还款信息修改成功!");
			BaseLogUtils.info(logger, "updateEaplySettleInfo", "修改数据,id["+lgcId+"].", CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "updateEaplySettleInfo", "修改数据失败,id["+lgcId+"]."+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误");
			BaseLogUtils.error(logger, "updateEaplySettleInfo", "修改数据失败,id["+lgcId+"]."+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
	
	private void uploadAttchment(HttpServletRequest request, DataResultVO result, Long id) {
		String attchmnt = request.getParameter("docArray");
		if(StringUtils.isNotEmpty(attchmnt)){
			//上传解析
			try{
				String cfgCd = PropertiesCacheUtils.getProperty(CustomerConstant.CST_BSCINFO_CFGCD);
				String cfgDtlCd = PropertiesCacheUtils.getProperty(CustomerConstant.CST_BSCINFO_CFGDTLCD);
				String tabNm = PropertiesCacheUtils.getProperty(CustomerConstant.CST_BSCINFO_TABNM);
				String cfgOrgCd = PropertiesCacheUtils.getProperty(CustomerConstant.CST_BSCINFO_CFGORG);
				Boolean attchmntPass = this.sysUlFilesRecService.addAttchmnt(String.valueOf(id), attchmnt, cfgCd, cfgDtlCd, tabNm, "客户主要信息附件!", null, null, false, cfgOrgCd);
				if(null == attchmntPass || attchmntPass == false){
					result.setInfo(result.getInfo()+"-附件上传失败!");
				}
			}catch(Exception e){
				result.setInfo(result.getInfo()+"-附件上传失败!");
			}
		}
	}
	
	/**
	 * 附件查询
	 * 
	 * @param condition
	 * @return
	 * @throws BaseException
	 */
	private List<SysUlDatCfgVO> searchSysUlDatCfgList(Long id) throws BaseException {
		// 查询资料配置，系统代码,组织架构代码,配置编号 ,业务主键
		SysUlDatCfgQueryCondition ulDatCfgQueryCondition = new SysUlDatCfgQueryCondition();
		ulDatCfgQueryCondition.setSysCd(CurrentThreadContext.getCurrentSysCd());// 系统代码

		ulDatCfgQueryCondition.setOrgCd(PropertiesCacheUtils.getProperty(CustomerConstant.CST_BSCINFO_CFGORG));// 组织架构代码
		// ulDatCfgQueryCondition.setOrgCd("10");// 组织架构代码
		ulDatCfgQueryCondition.setDataId(String.valueOf(id));// 业务主键
		List<String> cfgCdList = new ArrayList<>();
		ulDatCfgQueryCondition.setCfgCdList(cfgCdList);// 配置编号
		// cfgCdList.add("CST001");// 项目上传资料 配置编号
		cfgCdList.add(PropertiesCacheUtils.getProperty(CustomerConstant.CST_BSCINFO_CFGCD));// 项目上传资料 配置编号
		List<SysUlDatCfgDTO> sysUlDatCfgDTOList = this.uploadApiService.searchSysUlDatCfgList(ulDatCfgQueryCondition);

		return SysUlDatCfgVOTransform.toVOList(sysUlDatCfgDTOList);
	}
	
	/**
	 * 加载金融机构收款户选择框
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/initRecvList.do" ,method = {RequestMethod.GET})
	public @ResponseBody  List<BankAccInfoDTO>  initRecvList(HttpServletRequest request, HttpServletResponse response) {
		String instid = request.getParameter("insId");
		if (StringUtils.isEmpty(instid)) {
			return null;
		}
		BankAccInfoQueryCondition bankAccInfoQC = new BankAccInfoQueryCondition();
		bankAccInfoQC.setFundRasInsId(Long.parseLong(instid));
		bankAccInfoQC.setSysCd(CurrentThreadContext.getCurrentSysCd());
		bankAccInfoQC.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		List<BankAccInfoDTO> banklst = bankAccInfoApiService.searchList(bankAccInfoQC);
		
		return banklst;
	}
	
	/**
	 * 加载狮桥支付账户选择框
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/initPayList.do" ,method = {RequestMethod.GET})
	public @ResponseBody  List<SysBkAccInfoVO>  initPayList(HttpServletRequest request, HttpServletResponse response) {
		SysBkAccInfoQueryCondition qc = new SysBkAccInfoQueryCondition();
		qc.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		List<SysBkAccInfoVO> bkAccList = sysBkAccInfoService.searchList(qc);
		return bkAccList;
	}
	
	@RequestMapping(value = "/addPrjEaplySettleFlowStart.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object addPrjEaplySettleFlowStart(HttpServletRequest request, HttpServletResponse response) {

		String id = request.getParameter("id");
		String procDefKey = request.getParameter("procDefKey");
		String procDefId = request.getParameter("procDefId");
		String procNo = request.getParameter("procNo");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "addPrjEaplySettleFlowStart", SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY, CurrentThreadContext.getCurrentUserName());
			return result;
		}
		FlowStartParamsDTO flowStartParamsDTO = new FlowStartParamsDTO();
		try {
			//流程定义Key和流程定义ID 如果是前端选择的则直接指定,如果不是则系统自动按照配置选择唯一一条记录,如果找不到会提示
			flowStartParamsDTO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);
			flowStartParamsDTO.setWordsInTheTable(FncPrjEaplySettleConstant.REF_FLOW_S_H_FPES);
			flowStartParamsDTO.setProcDefKey(procDefKey);
			flowStartParamsDTO.setProcDefId(procDefId);
			flowStartParamsDTO.setProcNo(procNo);
			flowStartParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			flowStartParamsDTO.setBusinessKey(id);
			flowStartParamsDTO.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
			flowStartParamsDTO.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
			flowStartParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
			flowStartParamsDTO.setInitiator(String.valueOf(CurrentThreadContext.getCurrentUserId()));
			flowStartParamsDTO.setInitiatorNm(CurrentThreadContext.getCurrentUserName());
			flowStartParamsDTO.setProcPriority(FlowConstant.FLOW_PRIORITY_EMERGENCY);//优先级,可以在界面定义
			flowStartParamsDTO.setBusinessType(FncPrjEaplySettleConstant.FLOW_BUSINESS_TYP_FNC_PRJ_EARLY_SETTLE);//确认用不用
			flowStartParamsDTO.setModelTyp(FncPrjEaplySettleConstant.FLOW_MODEL_TYP_FPES);//需要和流程配置中的模块类型匹配
			flowStartParamsDTO.setSearchDesc(CurrentThreadContext.getCurrentOrgDispNm()+"、授信流程大字段参数未定!");
			DataResultDTO dataResultDTO = this.fncPrjEaplySettleService.addPrjEaplySettleFlowStart(flowStartParamsDTO);
			if(!dataResultDTO.getCode().equals(BaseExceptionConstant.BASE_EXCEPTION_CODE_200)){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL);
			}
			if(null!=dataResultDTO && null!=dataResultDTO.getData()){
				FlowStartedDTO flowStartedDTO = (FlowStartedDTO) dataResultDTO.getData();
				if(StringUtils.isNotBlank(flowStartedDTO.getNextOperUsrNames())){
	                result.setInfo("下一个节点操作人:"+flowStartedDTO.getNextOperUsrNames());
	            }else{
	                result.setInfo("流程发起成功");
	            }
				//录入资金系统接口付款表--陈君
				//this.fncCapPayeeInfoService.addCapEaplySettle(Long.parseLong(id));
			}
			/*if(null != dataResultDTO.getInfo() && StringUtils.isNotEmpty(dataResultDTO.getInfo())){
				StringBuffer info = new StringBuffer();
				info.append(result.getInfo());
				info.append(SysLogConstant.LOG_FLOW_NEXT_TASK_OPERATOR);
				info.append(dataResultDTO.getInfo());//操作人
				result.setInfo(info.toString());
			}*/
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.info(logger, "addPrjEaplySettleFlowStart", "错误[BaseException],请求参数：" + JSONObject.toJSONString(flowStartParamsDTO) + " -ERROR:" +e.getMessage(), CurrentThreadContext.getCurrentUserName());
			e.getStackTrace();
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "addPrjEaplySettleFlowStart", "错误[Exception],请求参数：" + JSONObject.toJSONString(flowStartParamsDTO) + " -ERROR:" +e.getMessage(), CurrentThreadContext.getCurrentUserName());
			e.getStackTrace();
		}
		return result;
	}
	
	
	/**
	 * 修改-主动还款信息
	 */
	@RequestMapping(value = "/getPayListInfo.do", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Object getPayListInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
	
		String prjLgcId = request.getParameter("prjLgcId");
		if (StringUtils.isEmpty(prjLgcId)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "提前还款项目逻辑编号不能为空!");
		}
		List<FncPrjPayTbInfoVO> FncPrjPayTbInfoList = new ArrayList<FncPrjPayTbInfoVO>();
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "信息查询成功!");
		try {
			FncPrjPayTbInfoList =this.fncPrjEaplySettleService.selectPrjPayTbInfoList(Long.valueOf(prjLgcId));
			result.setData(FncPrjPayTbInfoList);
			BaseLogUtils.info(logger, "getPayListInfo", "修改数据,项目逻辑编号["+prjLgcId+"].", CurrentThreadContext.getCurrentUserName());
		} catch (BaseException ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(ex.getMessage());
			BaseLogUtils.info(logger, "getPayListInfo", "修改数据失败,项目逻辑编号["+prjLgcId+"]."+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}catch (Exception ex) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("系统错误");
			BaseLogUtils.error(logger, "getPayListInfo", "修改数据失败,项目逻辑编号["+prjLgcId+"]."+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return result;
	}
}
